<%@page import="org.apache.commons.lang3.StringUtils"%>
<%@page import="com.kerrykidz.sales.dao.model.PosOrderEntity"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<jsp:include page="/common/commonCss.jsp"></jsp:include>
<jsp:include page="/common/commonJs.jsp"></jsp:include>
<script type="text/javascript"
	src="${basePath }commonJs/quinn_commons.js"></script>
<title>首页</title>
<script type="text/javascript">
	/* function printTicket(id) {
		$.ajax({
			url : "${basePath}order/printOrderDetail.shtml",
			type : "post",
			dataType : "json",
			data : {
				pkOrderId : id
			}
		});
	} */
	function printTicket(id) {
		/* js调用 */
		$.ajax({
			url:"${basePath}scmInvocing/productInfo/getOrderDetail.shtml",
			dataType:"json",
			data:{"pkOrderId":id},
			async:false,
			success:function(result){
				trimJsonArray(result);
				createProtype(result);
				openChild();
			}
		}); 
		/* function printTicket(id) { */
			/* $.ajax({
				url : "${basePath}order/printOrderDetail.shtml",
				type : "post",
				dataType : "json",
				data : {
					pkOrderId : id
				}
			}); */
	/* 	} */
	}
	//生成打印小票原型
	function createProtype(result){
		var base=result[0];
		var html="<div class=\"ticket\"><div><p><span class=\"vb\">"+base.brand+"</span></p></div>";
	    		html+="<div class=\"fz11 ticket_bo\"><table class=\"table_y\"><tr>";
	        	html+="<td>流水号："+base.shop+"</td>";
	            html+="<td>02/07/2014　15:25:25</td>";
	            html+="<td>收银：张三丰</td></tr></table></div>";
	    		html+="<div class=\"ticket_bo\"><table class=\"table_y\">";
	    		html+="<tr><th>商品</th><th>数量</th> <th>单价</th><th>金额</th></tr>";
	    		$(result).each(function(index,item){
		    		html+="<tr><td>"+item.itemName+"</td><td>"+item.qty+"</td><td>"+item.price+"</td><td>"+item.teaPrice+"</td></tr>";
	    		});
	    		html+="</table></div>";
	           	html+="<div class=\"ticket_bo\"><table class=\"table_y\">";
	           	html+="<tr><th>合计</th><td>￥"+base.totalPrice+"</td></tr>";
	           	html+="<tr><th>现金</th><td>￥"+base.payForCash+"</td></tr>";
	           	html+="<tr><th>余额</th><td>￥"+base.payForCz+"</td></tr>";
	            html+="<tr><th>刷卡</th><td>￥"+base.payForCard+"</td></tr></table></div><div>签名：</div></div>";
				$("#contentHtml").html(html);
				
	}
	function openChild(){
         	window.open("${basePath}plugin/PrintPage.jsp","abc",'width=800px,height=800px');
	}
</script>
</head>
<body class="bg">
	<div class="content m_auto">
		<div class="content_l mt10">
			<ul>
				<shiro:hasPermission name="goods/list.shtml">
					<li><a href="${basePath }goods/list.shtml"><i
							class="nav_icon_k"></i><br>商品</a></li>
				</shiro:hasPermission>
				<shiro:hasPermission name="order/shopCart.shtml">
					<li><a href="${basePath }order/shopCart.shtml"><i
							class="nav_icon_l"></i><br>购物篮</a></li>
				</shiro:hasPermission>
				<shiro:hasPermission name="order/list.shtml">
					<li class="content_hover"><a
						href="${basePath }order/list.shtml"><i class="nav_icon_m"></i><br>订单</a></li>
				</shiro:hasPermission>
			</ul>
		</div>
		<div class="content_r mt10">
			<div class="p20">
				<h1 class="f16">订单信息</h1>
				<div class="goods_order_top fixed mt10 f14">
					<ul class="ml10">
						<li><label>订单号：</label>${order.pkOrderId }</li>
						<li><label>客户姓名：</label>${order.cusName }</li>
						<li><label>当前操作人：</label>${order.operator }</li>
						<li><shiro:principal></shiro:principal></li>
					</ul>
				</div>
				<table class="table mt10">
					<tr>
						<th>序号</th>
						<th>商品编号</th>
						<th>商品名称</th>
						<th width="150">数量</th>
						<th>单价</th>
						<th>小计</th>
						<th>折扣率</th>
						<th>备注</th>
						<th>折后金额</th>
					</tr>
					<c:forEach var="p" items="${products }" varStatus="vs">
						<tr>
							<td>${vs.index+1 }</td>
							<td>${p.fkPrdId }</td>
							<td><c:choose>
									<c:when test="${p.type eq '1' }">
									${p.productName }
								</c:when>
									<c:otherwise>
									充值
								</c:otherwise>
								</c:choose></td>
							<c:choose>
								<c:when test="${p.type eq '1' }">
									<td>${p.count }</td>
									<td>${p.price }</td>
									<td>${p.price*p.count }</td>
								</c:when>
								<c:otherwise>
									<td>-</td>
									<td>-</td>
									<td>${p.count }</td>
								</c:otherwise>
							</c:choose>
							<td>${empty p.disValue ? '无' :p.disValue  }</td>
							<td>${p.discComments }</td>
							<td>${p.disPrice }</td>
						</tr>
					</c:forEach>
					<tr>
						<td colspan="9">
							<ul class="goods_ul fr p10">
								<!-- 非预付 -->
								<c:if test="${!isPrepay }">
									<c:set value="${order.paidAmount==null?0:order.paidAmount  }"
										var="paidAmount"></c:set>
									<li>商品总价：<span class="color_lv mlr5 f18">￥${order.amount }</span></li>
									<c:if test="${paidAmount>0 }">
										<li>已付金额：<span class="color_lv mlr5 f18">￥${paidAmount }</span></li>
									</c:if>
									<c:if test="${wbqje!=null and wbqje>0 }">
										<li>玩伴券金额：<span class="color_lv mlr5 f18">￥${wbqje }</span></li>
									</c:if>
									<c:if test="${giftPrice!=null and giftPrice>0 }">
										<li>礼券金额：<span class="color_lv mlr5 f18">${giftPrice }</span></li>
									</c:if>
									<c:if test="${hyxfzk!=null and hyxfzk>0 }">
										<li>会员续费优惠金额：<span class="color_lv mlr5 f18">${hyxfzk }</span></li>
									</c:if>
									<c:if test="${zkje!=null and zkje>0 }">
										<li>折扣金额<span class="color_lv mlr5 f18"><fmt:formatNumber
													value="${zkje}" pattern="￥.0#"></fmt:formatNumber></span></li>
									</c:if>
								</c:if>
							</ul>
						</td>
					</tr>
				</table>
				<c:if
					test="${order.retFlag == '0' && order.orderStatus != '1'  && (order.orderType eq '2' or order.orderType eq '3')}">
					<div class="mt10">
						<table class="table">
							<tr>
								<th>宴请单</th>
								<!-- <th>礼券</th> -->
							</tr>
							<tr>
								<td><input type="button" value="查看附件" class="btn_l"
									onclick="window.location.href='${basePath}common/showImage.shtml?imagePath=${order.fkFeteFile }'"></td>
								<!-- <td><input type="button" value="查看" class="btn_l"
									onclick="$('#exx').window('open')"></td> -->
							</tr>
						</table>
					</div>
				</c:if>

				<div class="clear"></div>
				<table class="table mt10">
					<tr>
						<th>操作人</th>
						<th>操作时间</th>
						<th>收银金额</th>
						<th>收银方式</th>
						<th>对应订单号</th>
						<th>操作描述</th>
					</tr>

					<c:forEach items="${records }" var="p">
						<tr>
							<td>${p.operator }</td>
							<td><fmt:formatDate value="${p.opeTime }" /></td>
							<td class=" color_org">￥${p.price }</td>
							<td><c:choose>
									<c:when test="${p.payMethod eq '1' }">
										现金
									</c:when>
									<c:when test="${p.payMethod eq '2' }">
										储值消费
									</c:when>
									<c:otherwise>
										银行卡
									</c:otherwise>
								</c:choose></td>
							<td class="lv">${p.id }</td>
							<td>${p.opeDesc }</td>
						</tr>
					</c:forEach>

				</table>
				<div class="btm_btn mt10">
					<dl>
						<c:if test="${order.orderStatus eq '2' }">
							<dd>
								<input type="button" class="btn" value="打印小票"
									onclick="printTicket('${order.pkOrderId}');">
							</dd>
						</c:if>
						<dd>
							<input type="button" class="btn" value="返回"
								onclick="history.go(-1)">
						</dd>
					</dl>
				</div>
			</div>
		</div>
	</div>


	<!---弹出层--->
	<div id="e" class="easyui-window" title="特殊折扣设置"
		data-options="modal:true,closed:true,iconCls:'icon-save'"
		style="width: 500px; height: 300px; position: relative;">
		<div class="margin_auto w300 pt30">
			<ul class="ul_label f14">
				<li><label>折扣率：</label><input type="text" class="iput_t"></li>
				<li><label>经理密码：</label><input type="text" class="iput_t"></li>
			</ul>
		</div>
		<div class="btm_btn btm_bg">
			<dl>
				<dd>
					<input type="button" class="btn" onclick="history.go(-1)"
						value="返回">
				</dd>
			</dl>
		</div>
	</div>
	<!---弹出层--->
	<!---弹出层--->
	<div id="exx" class="easyui-window" title="查看礼券"
		data-options="modal:true,closed:true,iconCls:'icon-save'"
		style="width: 500px; height: 350px; position: relative;">
		<div class="m10">
			<table class="table">
				<tr>
					<th>礼券号</th>
				</tr>
				<%
					PosOrderEntity order = (PosOrderEntity) request.getAttribute("order");
					if (StringUtils.isNotBlank(order.getGiftNo())) {
						String giftno[] = order.getGiftNo().split(",");
						for (String gn : giftno) {
				%>
				<tr>
					<td><%=gn%></td>
				</tr>
				<%
					}
					}
				%>
			</table>
		</div>
		<div class="btm_btn btm_bg">
			<dl>
				<dd>
					<input type="button" class="btn"
						onClick="$('#exx').window('close')" value="关闭">
				</dd>
			</dl>
		</div>
	</div>
	<!---弹出层--->

</body>
</html>